<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../static/修改课程.css">
    <link rel="stylesheet" href="../static/iconfont/iconfont.css">
    <title>修改课程</title>
</head>
<body>
<div class="head">
    <div class="header">&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;<img width=36 height=36 src="../static/xh.png"/><img width=180 height=36 src="../static/wz.png"/>
        <a href="/teacher/login" class="exit"><i class="iconfont icon-tuichu"></i>退出登录</a></div>
</div>
<div class="big_box">
    <div class="wrap">
        <div class="seg"></div>
        <div class="item_title">
            <b>教师端</b>
        </div>
        <div class = "seg"></div>
        <div class="item">
            <a href="http://localhost:8080/teacher/tutorial"><i class="iconfont icon-yixuan" ></i>&ensp;任教课程</a>
        </div>
        <div class="item">
            <a href="http://localhost:8080/teacher/up_course"><i class="iconfont icon-fabu" ></i>&ensp;发布课程</a>
        </div>
        <div class="item">
            <a href="http://localhost:8080/teacher/modify_course"><i class="iconfont icon-xiugai" ></i>&ensp;修改课程</a>
        </div>
        <div class="item">
            <a href="http://localhost:8080/teacher/delete_course"><i class="iconfont icon-shanchu" ></i>&ensp;删除课程</a>
        </div>
        <div class="item">
            <a href="教师个人信息"><i class="iconfont icon-gerenxinxi" ></i>&ensp;个人信息</a>
        </div>
    </div>
    <div class="delete">
        <div class="row">
            <h1>
                修改课程
            </h1>
            <div class="selected">
                <form action="/modify_search" method="post" >
                    请选择类别&nbsp;
                    <select id="classification" class="classification" style="color: #295287;">
                        <option value="1-1">公共课</option>
                        <option value="1-2">专业课</option>
                        <option value="2-1">通识课</option>
                    </select>
                    <input type="button" class="button" value="检索" onclick="search()"/>
                </form>
            </div>
            <div class="course_table" id="course_table" style="display: none;">
                <table id="table" class="table" >
                </table>
            </div>
        </div>

        <div class="modal" id="myModal" style="display: none;">
            <div class="modal-dialog">
                <form class="modal-content" method="post" id="Form" role="form">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" onclick="Default()">
                            <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                        </button>
                    </div>
                    <h4 class="modal-title">请修改课程</h4>
                    <div class="modal-body">
                        <form id="course_form">
                            <tr>
                                <td>课&ensp;程&ensp;号：<input placeholder="课程号" type="text" id="course_id" readonly="readonly"/><br /></td>
                                <td>课&ensp;程&ensp;名：<input placeholder="课程名" type="text" id="course_name"/><br /></td>
                                <td>课程时长：<input placeholder="课程时长" type="text" id="course_length"/></td><br />
                                <td>课程学分：<input placeholder="课程学分" type="text" id="course_score"/></td><br />
                                <td>上课时间：<input placeholder="上课时间" type="text" id="course_time"/></td><br />
                                <td>上课地点：<input placeholder="上课地点" type="text" id="course_classroom"/></td><br />
                                <td>可选人数：<input placeholder="可选人数" type="text" id="course_count"/></td><br />
                                <td>课程类别：<input placeholder="课程类别" type="text" id="course_classification"/></td><br />
                                <td>课程学期：<input placeholder="课程学期" type="text" id="course_term"/></td><br />
                                <td>授课教师：<input placeholder="授课教师" type="text" id="course_teacher" readonly="readonly"/></td><br /><br/>
                            </tr>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn_default" data-dismiss="modal" onclick="Default()">取消</button>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
                            <button type="button" class="btn_primary" onclick="change()">确定</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" language="JavaScript">
    function  Default() {
        document.getElementById("myModal").style.display="none";
    }
    function logout() {
        $.ajax({
            async:false,
            type:"post",
            url:'/logout',
            contentType:"application/x-www-form-urlencoded;charset=utf-8",
            dataType:"text",
            complete:function(){
                window.location.reload();
            }
        })
    }
    $("#modify").click(function () {
        $("#modal_name").text("修改课程");
        $("#btn_primary").css("display", "");
        $("#myModal").modal({
            backdrop: "static"
        })
    })
    function search(){
        document.getElementById("course_table").style.display="block";
        var select=document.getElementById("classification");
        var classify=select.value;
        $.ajax({
                type: "POST",
                url: "/teacher/ututorial",
                data:{"classify_id":classify},
                dataType: "json",
                success: function (dat) {
                    if(dat.c_count==0) {
                        var ltr = '<tr><th>您暂未发布此类课程!</th></tr>';
                        $("table").empty();
                        $("table").append(ltr);
                    }
                    //  window.location.href="http://localhost:8080/teacher/tutorial";
                    else{
                        var ltr='<tr><th>'+"课程号"+
                            '</th><th>'+"课程名"+
                            '</th><th>'+"课程时长"+
                            '</th><th>'+"课程学分"+
                            '</th><th>'+"上课时间"+
                            '</th><th>'+"上课地点"+
                            '</th><th>'+"可选人数"+
                            '</th><th>'+"课程类别"+
                            '</th><th>'+"授课老师"+
                            '</th><th>'+"学期"+
                            '</th><th>'+"操作"+
                            '</th></tr>';
                        var course_th=dat.course_th;
                        var cindex=1;
                        $.each(course_th,function(index,course){
                            var term;
                            if(course.term=="1"){term="大一上学期"}
                            else if(course.term=="2"){term="大一下学期"}
                            else if(course.term=="3"){term="大二上学期"}
                            else if(course.term=="4"){term="大二下学期"}
                            else if(course.term=="5"){term="大三上学期"}
                            else if(course.term=="6"){term="大三下学期"}
                            var tr='<tr><td>'+course.courseid+
                                '</td><td>'+course.coursename+
                                '</td><td>'+course.coursetime+
                                '</td><td>'+course.coursescore+
                                '</td><td>'+course.time+
                                '</td><td>'+course.site+
                                '</td><td>'+course.number+
                                '</td><td>'+course.classify+
                                '</td><td>'+course.teacher+
                                '</td><td>'+term+
                                '</td><td><button id="'+cindex+'"class="modify" type="button" onclick="doEdit(this)">修改</button></td>';
                            ltr=ltr+tr;
                            cindex=cindex+1;
                            //document.getElementById("button_s").value=course.courseid;
                        })
                        $("table").empty();
                        $("table").append(ltr);
                    }
                },
                error : function (XMLHttpRequest, textStatus, errorThrown) {
                    console.log("错误");
                    // 状态码
                    console.log(XMLHttpRequest.status);
                    // 状态
                    console.log(XMLHttpRequest.readyState);
                    // 错误信息
                    console.log(textStatus);
                }
            }
        )

    }
    function doEdit(self){
        document.getElementById("myModal").style.display="block";
        $('#myModal').modal('show');   // 初始化后立即调用 show 方法
        var index=self.getAttribute("id");
        var arr=[];
        $("table tr").eq(index).find("td").each(
            function (){
                arr.push($(this).text());
            }
        );
        $("#course_id").val(arr[0]);
        $("#course_name").val(arr[1]);
        $("#course_length").val(arr[2]);
        $("#course_score").val(arr[3]);
        $("#course_time").val(arr[4]);
        $("#course_classroom").val(arr[5]);
        $("#course_count").val(arr[6]);
        $("#course_classification").val(arr[7]);
        $("#course_teacher").val(arr[8]);
        $("#course_term").val(arr[9]);
    }
    function change(){
        $.ajax({
            type:"POST",
            url:"/teacher/umodify_course",
            dataType:"json",
            data:{
                "cid":$("#course_id").val(),
                "cname":$("#course_name").val(),
                "clength":$("#course_length").val(),
                "cscore":$("#course_score").val(),
                "time":$("#course_time").val(),
                "csite":$("#course_classroom").val(),
                "cnumber":$("#course_count").val(),
                "classify":$("#course_classification").val(),
                "cteacher":$("#course_teacher").val(),
                "cterm":$("#course_term").val()
            },
            success:function(dat){
                console.log(dat.stat);
                if(dat.stat==2){
                    alert("您已有课程在此上课时间！");
                }
                else{
                    alert("修改成功！");
                    search();
                    // window.location.reload();
                    document.getElementById("myModal").style.display="none";
                }
            },
            error : function (XMLHttpRequest, textStatus, errorThrown) {
                console.log("错误");
                // 状态码
                console.log(XMLHttpRequest.status);
                // 状态
                console.log(XMLHttpRequest.readyState);
                // 错误信息
                console.log(textStatus);
            }
        })
    }
</script>
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.24/assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.24/dist/js/bootstrap.min.js"></script>
<!-- Just to make our placeholder images work. Don't actually copy the next line! -->
<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.24/assets/js/vendor/holder.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.24/assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>